package com.xy.sql.xml.node.impl;


import com.xy.sql.xml.core.XySQLExePara;
import com.xy.sql.xml.core.XySQLTaskContext;
import com.xy.sql.xml.itf.XySQLRegister;
import com.xy.sql.xml.kit.XySQLScriptKit;
import com.xy.sql.xml.node.XySQLSuperNode;

import java.util.List;

public class XySQLSetNode extends XySQLSuperNode {

    @Override
    public String getTag() {
        return "set";
    }

    @Override
    public XySQLSuperNode clone() {
        return new XySQLSetNode();
    }

    public List<XySQLExePara> boundSql(XySQLTaskContext task) throws Exception {
        List<XySQLExePara> dataList = super.boundSql(task);
        if (dataList.size() > 0) {
            XySQLExePara para;
            for (int i = dataList.size() - 1; i >= 0; i--) {
                para = dataList.get(i);
                String sql = para.getSqlFragment();
                if (sql == null || sql.trim().length() == 0) {
                    XySQLRegister.getLogger().debug("SET 内部SQL片段过小(" + sql + ")");
                    continue;
                }
                sql = XySQLScriptKit.trim(sql, ",", ",");
                dataList.set(i, new XySQLExePara(" SET " + sql + " ", para.getValue(), para.isContainNull()));
                break;
            }
        }
        return dataList;
    }
}
